package calendar;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author LiuYan
 * @date 2021/11/23 13:44
 * DateTimeFormatter:格式化时间/日期
 */
public class Part17 {
    public static void main(String[] args) {
        // 日期格式化
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_DATE;
        LocalDateTime now = LocalDateTime.now();
        String format = now.format(dateTimeFormatter);
        System.out.println(format);
        // 自定义日期格式化
        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        String format1 = dateTimeFormatter1.format(now);
        System.out.println(format1);
        // 将字符串转成日期格式
        LocalDateTime parse = LocalDateTime.parse(format1, DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss"));
        System.out.println(parse);

    }

}
